package com.tanhua.server.controller;


import com.tanhua.server.service.SoulService;
import com.tanhua.server.vo.Answer;
import com.tanhua.server.vo.ReportVo;
import com.tanhua.server.vo.SoulVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("testSoul")
public class SoulController {

    @Autowired
    private SoulService soulService;

    /**
     * 测灵魂-问卷列表
     * @return
     */
    @GetMapping
    public ResponseEntity<List<SoulVo>> soulQustionsList(){
        try {
            List<SoulVo> qustionsList =  soulService.querySoulQustionsList();
            return ResponseEntity.ok(qustionsList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * 测灵魂-提交问卷答案
     * @return
     */
    @PostMapping
    public ResponseEntity<String> SaveSoulAnswer(@RequestBody Map<String,List<Answer>> answers){
        try {
            String reportId = soulService.SaveSoulAnswer(answers);
            return ResponseEntity.ok(reportId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * 测灵魂-查看结果
     * @return
     */
    @GetMapping("/report/{id}")
    public ResponseEntity<ReportVo> SaveSoulAnswer(@PathVariable("id") String reportId){
        try {
            ReportVo reportVo = soulService.queryReport(reportId);
            return ResponseEntity.ok(reportVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
